package NonBinaryAttributes;
import java.util.ArrayList;


public class AssociationRule implements Comparable{
	private ItemSet antecedent;
	private ItemSet consequent;
	private ArrayList<Item> antecedentItems;
	private ArrayList<Item> consequentItems;
	private double confidence;
	
	
	public AssociationRule(ItemSet ant, ItemSet con) {
		antecedent = ant;
		consequent = con;
	}

	public AssociationRule() {
		antecedentItems = new ArrayList<Item>();
		consequentItems = new ArrayList<Item>();
	}
	
	public void addToAntecedent(Item i) {
		antecedentItems.add(i);
	}
	
	public void addToConsequent(Item i) {
		consequentItems.add(i);
	}

	public void computeConfidence(int fullSetSupport) {
		confidence = (double)(fullSetSupport)/antecedent.getSupport();
	}
	
	public double getConfidence() {
		return confidence;
	}
	
	@Override
	public String toString() {
		return "Confidence= "+confidence +" - " + antecedent.simple() + " -> " + consequent.simple();
	}

	@Override
	public int compareTo(Object obj) {
		if(!(obj instanceof AssociationRule)) return 0;
		AssociationRule toCompare = (AssociationRule)obj;
		return (int)Math.signum(confidence - toCompare.confidence);
	}
	
}
